<html>
<head><meta charset="utf-8"><title>Cross-crate static access · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html">Cross-crate static access</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195628665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195628665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195628665">(Apr 28 2020 at 21:20)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> is it possible that accessing the memory backing a static in another crate does not work? I found a (miri-unleash) soundness issue related to <a href="https://github.com/rust-lang/const-eval/issues/42" title="https://github.com/rust-lang/const-eval/issues/42">https://github.com/rust-lang/const-eval/issues/42</a>, and in exploring that also ran into an ICE where <code>unwrap_memory</code> fails ("expected allocation ID alloc0 to point to memory") -- which is <em>not</em> the failure mode I expected.</p>



<a name="195628725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195628725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195628725">(Apr 28 2020 at 21:21)</a>:</h4>
<p>just replacing a static by a const makes that ICE go away</p>



<a name="195628808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195628808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195628808">(Apr 28 2020 at 21:22)</a>:</h4>
<p>but an <em>immutable</em> static still ICEs</p>



<a name="195628913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195628913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195628913">(Apr 28 2020 at 21:23)</a>:</h4>
<p>so I am wondering if rlib encoding/decoding somehow treats statics and consts differently</p>



<a name="195632489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195632489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195632489">(Apr 28 2020 at 21:55)</a>:</h4>
<p>I hit that error on local statics as well, they're represented differently regardless of rlib encoding</p>



<a name="195632638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195632638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195632638">(Apr 28 2020 at 21:56)</a>:</h4>
<p>hm, on the one hand I guess it's good that it's not some cross-crate magic</p>



<a name="195632684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195632684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195632684">(Apr 28 2020 at 21:56)</a>:</h4>
<p>but I still wonder what the difference is, then. maybe something about const normalization...</p>



<a name="195632735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195632735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195632735">(Apr 28 2020 at 21:57)</a>:</h4>
<p>there are so many fragile moving pieces here, I'd love to find some way to make this all nice and clean and "obviously correct" but I don't know how :/</p>



<a name="195632932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195632932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195632932">(Apr 28 2020 at 21:58)</a>:</h4>
<p>right- from what I gathered, there are two allocation IDs floating around for statics. one is opaque and the other is the "real" one but it's only used in limited circumstances (that <code>try_unwrap_memory</code> change I tried is because of this)</p>



<a name="195633949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195633949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195633949">(Apr 28 2020 at 22:06)</a>:</h4>
<p>ah... good point</p>



<a name="195634008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195634008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195634008">(Apr 28 2020 at 22:07)</a>:</h4>
<p>so pattern matching is missing the logic to follow the "lazy" allocid (the ones that map to <code>GlobalAlloc::Static</code>)</p>



<a name="195634028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195634028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195634028">(Apr 28 2020 at 22:07)</a>:</h4>
<p>which makes sense, it should never encounter any statics</p>



<a name="195634090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Cross-crate%20static%20access/near/195634090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Cross-crate.20static.20access.html#195634090">(Apr 28 2020 at 22:07)</a>:</h4>
<p>this basically accidentally served as a third line of defense after static const checks and dynamic const checks, thus preventing the unsoundness with an ICE</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>